package com.deng.template.common.model;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author Deng
 * @date 2022/9/25 3:16
 */
@Data
@Accessors(chain = true)
public class CnResult<T> {
    private Boolean success;
    private String errorMsg;
    private T data;

    public CnResult(Boolean success, String errorMsg, T data) {
        this.success = success;
        this.errorMsg = errorMsg;
        this.data = data;
    }

    public static <T> CnResult<T> ofSuccess(T data){
        return new CnResult<>(true, null, data);
    }

    public static <T> CnResult<T> ofFail(T data){
        return new CnResult<>(false, null, data);
    }

    public static <T> CnResult<T> ofFail(T data, String errorMsg){
        return new CnResult<>(false, errorMsg, data);
    }
}